package com.jsbs.iam.auth.controller;

import com.github.pagehelper.PageInfo;
import com.jsbs.iam.auth.constant.Constants;
import com.jsbs.iam.auth.dto.*;
import com.jsbs.iam.auth.param.IamApplyDetaislParam;
import com.jsbs.iam.auth.param.IamRoleQueryUserParam;
import com.jsbs.iam.auth.param.IamRoleRemoveUserParam;
import com.jsbs.iam.auth.service.IamRoleManagerService;
import com.jsbs.iam.auth.vo.IamUserInfoVo;
import com.jsbs.iam.common.core.dto.Result;
import com.jsbs.iam.common.core.utils.Json;
import com.jsbs.iam.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @ClassName: IamRoleManagerController
 * @Author: tenghuawei
 * @Date: 2022/12/26 11:47
 * @Description:
 */

@Slf4j
@RestController
@RequestMapping("/iam/auth/roleManager")
public class IamRoleManagerController extends BaseController{

    @Autowired
    IamRoleManagerService iamRoleManagerService;


    /**
     * 功能描述：根据角色编码和角色名称，模糊查询普通角色列表
     * @param iamRoleCreateDto
     * @return Result
     */
    @PostMapping("/queryIamRole")
    public Result queryIamRole (@RequestBody IamRoleCreateDto iamRoleCreateDto, HttpServletRequest request) {
        try {
            // 普通角色由普管来创建，并且挂靠至普管角色下；普通角色表+用户组表都加普管角色字段
            String adminRoleCode = request.getHeader(Constants.ADMIN_ROLE_CODE);
            if(StringUtils.isBlank(adminRoleCode)){
                return Result.failWithMsg("管理员角色编码不可为空！");
            }
            iamRoleCreateDto.setAdminRoleCode(adminRoleCode);
            log.info("Route=>IamRoleManagerController method=>queryIamRole  查询角色列表条件入参为：{} ", Json.toJsonString(iamRoleCreateDto));
            PageInfo pageInfo = iamRoleManagerService.queryIamRole(iamRoleCreateDto);
            if(0==pageInfo.getTotal()){
                return Result.failWithMsg("无数据！");
            }
            return Result.success("角色列表查询成功！",pageInfo);
        }catch (Exception e){
            log.error("Route=>IamRoleManagerController method=>queryIamRole 查询角色列表异常：{},入参为：{}", e.getMessage(), Json.toJsonString(iamRoleCreateDto));
            return handleException(e);
        }
    }
    /**
     * 功能描述：角色新建
     * @param iamRoleCreateDto
     * @return Result
     */
    @PostMapping("/roleCreate")
    public Result roleCreate (@RequestBody IamRoleCreateDto iamRoleCreateDto, HttpServletRequest request) {
        try {
            // 获取当前登录人
            String userCode = (String) request.getHeader(Constants.USER_CODE);
            //先使用伪数据
//            userCode="admin";
            if (StringUtils.isBlank(userCode)) {
                return Result.failWithMsg("当前登录状态异常！");
            }
            //归属租户
            String companyCode = (String) request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
//            companyCode="000001";
            if(StringUtils.isBlank(companyCode)){
                return Result.failWithMsg("当前登录归属租户为空！");
            }
            String adminRoleCode = request.getHeader(Constants.ADMIN_ROLE_CODE);
            if(StringUtils.isBlank(adminRoleCode)){
                return Result.failWithMsg("管理员角色编码不可为空！");
            }
            iamRoleCreateDto.setAdminRoleCode(adminRoleCode);
            if(StringUtils.isBlank(iamRoleCreateDto.getRoleName()) || iamRoleCreateDto.getRoleName().length() > 30){
                return Result.failWithMsg("角色名称为空或者长度超过30！");
            }
            if(StringUtils.isNotBlank(iamRoleCreateDto.getRoleInfo()) && iamRoleCreateDto.getRoleInfo().length() > 200){
                return Result.failWithMsg("角色描述长度超过200！");
            }
            iamRoleCreateDto.setCreatePerson(userCode);
            iamRoleCreateDto.setCompanyCode(companyCode);
            iamRoleCreateDto.setUpdatePerson(userCode);
            iamRoleCreateDto.setAdminRoleCode(adminRoleCode);
            int roleCreate = iamRoleManagerService.roleCreate(iamRoleCreateDto);
            if(0==roleCreate){
                return Result.failWithMsg("新建角色失败！");
            }
            return Result.successWithMsg("新建角色成功！");
        }catch (Exception e) {
            log.error("Route=>IamRoleManagerController method=>roleCreate 角色新建异常：{},入参为：{}", e.getMessage(), Json.toJsonString(iamRoleCreateDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色编辑
     * @param iamRoleCreateDto
     * @return Result
     */
    @PostMapping("/roleEdit")
    public Result roleEdit (@RequestBody IamRoleCreateDto iamRoleCreateDto, HttpServletRequest request) {
        try {
            //  获取当前登录人
            String userName = (String) request.getHeader(Constants.NAME);
            //先使用伪数据
//            userName="admin";
            if (StringUtils.isBlank(userName)) {
                return Result.failWithMsg("当前登录状态异常！");
            }
            //归属租户
            String companyCode = (String) request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
//            companyCode="000001";
            if(StringUtils.isBlank(companyCode)){
                return Result.failWithMsg("当前登录归属租户为空！");
            }
            String adminRoleCode = request.getHeader(Constants.ADMIN_ROLE_CODE);
            if(StringUtils.isBlank(adminRoleCode)){
                return Result.failWithMsg("管理员角色编码不可为空！");
            }
            if(StringUtils.isBlank(iamRoleCreateDto.getRoleCode())){
                return Result.failWithMsg("普通用户角色编码不可为空！");
            }
            if(StringUtils.isBlank(iamRoleCreateDto.getRoleName()) || iamRoleCreateDto.getRoleName().length()>30){
                return Result.failWithMsg("角色名称为空或者长度超过30！");
            }
            if(StringUtils.isNotBlank(iamRoleCreateDto.getRoleInfo()) && iamRoleCreateDto.getRoleInfo().length()>200){
                return Result.failWithMsg("角色描述长度超过200！");
            }

            iamRoleCreateDto.setUpdatePerson(userName);
            iamRoleCreateDto.setCompanyCode(companyCode);
            iamRoleCreateDto.setAdminRoleCode(adminRoleCode);
            int roleCreate = iamRoleManagerService.roleEdit(iamRoleCreateDto);
            if(0==roleCreate){
                return Result.failWithMsg("角色编辑失败！");
            }
            return Result.successWithMsg("角色编辑成功！");
        }catch (Exception e) {
            log.error("Route=>IamRoleManagerController method=>roleEdit 角色编辑异常：{}，入参为：{}", e.getMessage(), Json.toJsonString(iamRoleCreateDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色删除
     * @param iamRoleDeleteDto
     * @return Result
     */
    @PostMapping("/roleDelete")
    public Result roleDelete(@RequestBody IamRoleDeleteDto iamRoleDeleteDto,HttpServletRequest request) {
        try {
            // 获取当前登录人
            String userName = (String) request.getHeader(Constants.NAME);
            // 先使用伪数据
//            userName="admin";
            if (StringUtils.isBlank(userName)) {
                return Result.failWithMsg("当前登录状态异常！");
            }
            //归属租户
            String companyCode = (String) request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
            companyCode="000001";
            if(StringUtils.isBlank(companyCode)){
                return Result.failWithMsg("当前登录归属租户为空！");
            }
            String adminRoleCode = request.getHeader(Constants.ADMIN_ROLE_CODE);
            if(StringUtils.isBlank(adminRoleCode)){
                return Result.failWithMsg("管理员角色编码不可为空！");
            }
            if(CollectionUtils.isEmpty(iamRoleDeleteDto.getRoleCode())){
                return Result.failWithMsg("请至少选择一条角色信息进行删除！");
            }
            iamRoleDeleteDto.setCompanyCode(companyCode);
            iamRoleDeleteDto.setAdminRoleCode(adminRoleCode);
            log.info("Route=>IamRoleManagerController method=>roleDelete 角色删除入参：{}",Json.toJsonString(iamRoleDeleteDto));
            return iamRoleManagerService.roleDelete(iamRoleDeleteDto);
        }catch (Exception e){
            log.error("Route=>IamRoleManagerController method=>roleDelete 角色删除异常：{}，入参为：{}", e.getMessage(),Json.toJsonString(iamRoleDeleteDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色启用和禁用; 0:禁用；1:启用；（说明：角色禁用后，该角色对应的组织、应用、菜单或按钮关联关系，仍然存在）
     * @param iamRoleUpdateStatusDto
     * @return Result
     */
    @PostMapping("/updateRoleStatus")
    public Result updateRoleStatus(@RequestBody IamRoleUpdateStatusDto iamRoleUpdateStatusDto , HttpServletRequest request) {
        log.info("Route==>IamRoleManagerController method=updateRoleStatus 角色启用/停用入参：{}", Json.toJsonString(iamRoleUpdateStatusDto));
        try {
            // 获取当前登录人
            String userName = (String) request.getHeader(Constants.NAME);
            //先使用伪数据
//            userName="admin";
            if (StringUtils.isEmpty(userName)) {
                return Result.failWithMsg("当前登录状态异常!");
            }
            //归属租户
            String companyCode = (String) request.getHeader("companyCode");
            //companyCpde先使用伪数据
            companyCode="000001";
            if(StringUtils.isBlank(companyCode)){
                return Result.failWithMsg("当前登录归属租户为空！");
            }
            iamRoleUpdateStatusDto.setUpdatePerson(userName);
            iamRoleUpdateStatusDto.setCompanyCode(companyCode);
            log.info("Route==>IamRoleManagerController method=updateRoleStatus 角色启用/停用入参：{}",Json.toJsonString(iamRoleUpdateStatusDto));
            // 启用/禁用角色
            return iamRoleManagerService.updateRoleStatus(iamRoleUpdateStatusDto);
        } catch (Exception e) {
            log.error("Route==>IamRoleManagerController method=updateRoleStatus 角色启用/停用异常: {}，入参：{}",e.getMessage(), Json.toJsonString(iamRoleUpdateStatusDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色关联用户查询——可根据用户编码、姓名，模糊查询某个角色下所有绑定的用户
     * @param iamRoleQueryUserParam
     * @return Result
     */
    @PostMapping("/queryRoleBindUsers")
    public Result queryRoleBindUsers(HttpServletRequest request,@RequestBody IamRoleQueryUserParam iamRoleQueryUserParam) {
        try {
            //归属租户
            String companyCode = (String) request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
//            companyCode="000001";
            if(StringUtils.isBlank(companyCode)){
                return Result.failWithMsg("当前登录归属租户为空！");
            }
            if(Objects.isNull(iamRoleQueryUserParam.getRoleCode())){
                return Result.failWithMsg("角色编码为空，请点击【人员列表】菜单链接！");
            }
            iamRoleQueryUserParam.setCompanyCode(companyCode);
            log.info("Route==>IamRoleManagerController method=queryRoleBindUsers 查询某个角色下所有绑定的用户入参：{}",Json.toJsonString(iamRoleQueryUserParam));
            PageInfo<IamUserInfoVo> pageInfo = iamRoleManagerService.queryRoleBindUsers(iamRoleQueryUserParam);
            if(0==pageInfo.getTotal()){
                return Result.failWithMsg("未找到相关数据，建议您更换筛选条件");
            }
            return Result.success("查询该角色下绑定的用户成功！",pageInfo);
        } catch (Exception e) {
            log.error("Route==>IamRoleManagerController method=queryRoleBindUsers 查询某个角色下所有绑定的用户异常: {}，入参：{}",e.getMessage(),Json.toJsonString(iamRoleQueryUserParam));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色移除用户
     * @param iamRoleRemoveUserParam
     * @return Result
     */
    @PostMapping("/roleRemoveUsers")
    public Result roleRemoveUsers(@RequestBody IamRoleRemoveUserParam iamRoleRemoveUserParam) {
        try {
            if(Objects.isNull(iamRoleRemoveUserParam.getRoleCode())) {
                return Result.failWithMsg("角色编码为空，请点击【人员列表】菜单链接！");
            }
            if(CollectionUtils.isEmpty(iamRoleRemoveUserParam.getUserCodes())) {
                return Result.failWithMsg("请至少勾选一条该角色下绑定的用户信息！");
            }
            log.info("Route==>IamRoleManagerController method=roleRemoveUsers 角色移除用户入参：{}",Json.toJsonString(iamRoleRemoveUserParam));
            int roleRemoveUsers = iamRoleManagerService.roleRemoveUsers(iamRoleRemoveUserParam);
            if(0==roleRemoveUsers){
                return Result.failWithMsg("角色移除用户失败！");
            }
            return Result.successWithMsg("角色移除用户成功！");
        } catch (Exception e) {
            log.error("Route==>IamRoleManagerController method=roleRemoveUsers 角色移除用户异常: {}，入参：{}",e.getMessage(),Json.toJsonString(iamRoleRemoveUserParam));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色下还未绑定的用户
     * @param iamRoleQueryUserParam
     * @return Result
     */
    @PostMapping("/queryRoleNotBindUsers")
    public Result queryRoleNotBindUsers(@RequestBody IamRoleQueryUserParam iamRoleQueryUserParam) {
        try {
            if(Objects.isNull(iamRoleQueryUserParam.getRoleCode())) {
                return Result.failWithMsg("角色编码为空，请点击【人员列表】菜单链接！");
            }
            log.info("Route==>IamRoleManagerController method=queryRoleNotBindUsers 查询该角色下还未绑定的用户信息入参：{}",Json.toJsonString(iamRoleQueryUserParam));
            PageInfo<IamUserInfoVo> pageInfo = iamRoleManagerService.queryRoleNotBindUsers(iamRoleQueryUserParam);
            if(CollectionUtils.isEmpty(pageInfo.getList())){
                return Result.failWithMsg("未找到相关数据，建议您更换筛选条件！");
            }
            return Result.success("查询该角色下还未绑定的用户信息成功！",pageInfo);
        } catch (Exception e) {
            log.error("Route==>IamRoleManagerController method=queryRoleNotBindUsers 查询该角色下还未绑定的用户信息异常: {}，入参：{}",e.getMessage(),Json.toJsonString(iamRoleQueryUserParam));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色绑定用户
     * @param iamRoleBindUserDto
     * @return Result
     */
    @PostMapping("/roleBindUsers")
    public Result roleBindUsers(HttpServletRequest request, @RequestBody IamRoleBindUserDto iamRoleBindUserDto) {
        try {
            // 获取当前登录人
            String userName = (String) request.getSession().getAttribute("userName");
            //先使用伪数据
//            userName="admin";
            if (StringUtils.isBlank(userName)) {
                return Result.failWithMsg("当前登录状态异常！");
            }

            //归属租户
            String companyCode = request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
            companyCode="000001";
            if (StringUtils.isBlank(companyCode)) {
                return Result.failWithMsg("当前归属租户状态异常！");
            }
            if(Objects.isNull(iamRoleBindUserDto.getRoleCode())) {
                return Result.failWithMsg("角色编码为空，请点击【人员列表】菜单链接后，才能在该角色下新增绑定用户！");
            }
            if(CollectionUtils.isEmpty(iamRoleBindUserDto.getUserCodes())) {
                return Result.failWithMsg("请至少勾选一条该角色下需要绑定的用户信息！");
            }

            iamRoleBindUserDto.setCreatePerson(userName);
            iamRoleBindUserDto.setCompanyCode(companyCode);
            log.info("Route==>IamRoleManagerController method=>roleBindUsers 角色绑定用户入参：{}",Json.toJsonString(iamRoleBindUserDto));
            int roleBindUsers = iamRoleManagerService.roleBindUsers(iamRoleBindUserDto);
            if(0==roleBindUsers){
                return Result.failWithMsg("角色绑定用户失败！");
            }
            return Result.successWithMsg("角色绑定用户成功！");
        } catch (Exception e) {
            log.error("Route==>IamRoleManagerController method=>roleBindUsers 角色绑定用户异常: {}，入参：{}",e.getMessage(),Json.toJsonString(iamRoleBindUserDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色按组织绑定用户
     * @param iamRoleBindUserByOrgDto
     * @return Result
     */ // todo 组织范围
    @PostMapping("/roleBindUsersByOrg")
    public Result roleBindUsersByOrg(HttpServletRequest request, @RequestBody IamRoleBindUserByOrgDto iamRoleBindUserByOrgDto) {
        try {
            // 获取当前登录人
            String userName = (String) request.getHeader(Constants.NAME);
            //先使用伪数据
//            userName="admin";
            if (StringUtils.isBlank(userName)) {
                return Result.failWithMsg("当前登录状态异常！");
            }
            //归属租户
            String companyCode = (String) request.getSession().getAttribute("companyCode");
            //companyCpde先使用伪数据
            companyCode="000001";
            if (StringUtils.isBlank(companyCode)) {
                return Result.failWithMsg("当前归属租户状态异常！");
            }
            if(Objects.isNull(iamRoleBindUserByOrgDto.getRoleCode())) {
                return Result.failWithMsg("角色编码为空，请点击【人员列表】菜单链接后，才能在该角色按组织绑定用户！");
            }
            if(Objects.isNull(iamRoleBindUserByOrgDto.getOrgTypeCode())) {
                return Result.failWithMsg("组织类型编码不可为空！");
            }
            if(CollectionUtils.isEmpty(iamRoleBindUserByOrgDto.getOrgCodes())) {
                return Result.failWithMsg("没有勾选任何的组织或岗位！");
            }
            iamRoleBindUserByOrgDto.setCreatePerson(userName);
            iamRoleBindUserByOrgDto.setCompanyCode(companyCode);
            log.info("Route==>IamRoleManagerController method=>roleBindUsersByOrg 角色绑定用户入参：{}",Json.toJsonString(iamRoleBindUserByOrgDto));
            iamRoleManagerService.roleBindUsersByOrg(iamRoleBindUserByOrgDto);
            return Result.successWithMsg("角色按组织绑定用户成功！");
        } catch (Exception e) {
            log.error("Route==>IamRoleManagerController method=>roleBindUsersByOrg 角色按组织绑定用户异常: {}，入参：{}",e.getMessage(),Json.toJsonString(iamRoleBindUserByOrgDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：获取某个角色下某个组织树下已经勾选的组织或岗位，回填
     * @param iamOrgInfoAlreadySelectDto
     * @return Result
     */
    @PostMapping("/getAlreadyOrgThreeInfo")
    public Result getAlreadyOrgThreeInfo(HttpServletRequest request,@RequestBody IamOrgInfoAlreadySelectDto iamOrgInfoAlreadySelectDto) {
        try {
            //归属租户
            String companyCode = (String) request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
//            companyCode="000001";
            if (StringUtils.isBlank(companyCode)) {
                return Result.failWithMsg("当前归属租户状态异常！");
            }
            if(Objects.isNull(iamOrgInfoAlreadySelectDto.getRoleCode())){
                return Result.failWithMsg("角色编码不可为空！");
            }
            if(Objects.isNull(iamOrgInfoAlreadySelectDto.getOrgTypeCode())){
                return Result.failWithMsg("组织类型编码不可为空！");
            }
            iamOrgInfoAlreadySelectDto.setCompanyCode(companyCode);
            log.info("Route=>IamRoleManagerController method=>getAlreadyOrgThreeInfo 查询应用类型下的菜单树入参：{}", Json.toJsonString(iamOrgInfoAlreadySelectDto));
            List<String> alreadyOrgThreeInfo = iamRoleManagerService.getAlreadyOrgThreeInfo(iamOrgInfoAlreadySelectDto);
            return Result.success("查询该角色下组织树中已经勾选的组织或岗位成功！",alreadyOrgThreeInfo);
        }catch (Exception e){
            log.error("Route=>IamRoleManagerController method=>getAlreadyOrgThreeInfo 查询该角色下组织树中已经勾选的组织或岗位异常：{},入参为：{}", e.getMessage(), Json.toJsonString(iamOrgInfoAlreadySelectDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色授权应用系统
     * @param iamRoleAuthorizedDto
     * @return Result
     */
    @PostMapping("/roleAuthorizedApplication")
    public Result roleAuthorizedApplication(HttpServletRequest request, @RequestBody IamRoleAuthorizedDto iamRoleAuthorizedDto)  {
        try {
            String adminRoleCode = request.getHeader(Constants.ADMIN_ROLE_CODE);
            if(StringUtils.isBlank(adminRoleCode)){
                return Result.failWithMsg("管理员角色编码不可为空！");
            }
            // 获取当前登录人
            String userName = (String) request.getHeader(Constants.NAME);
            //先使用伪数据
//            userName="admin";
            if (StringUtils.isBlank(userName)) {
                return Result.failWithMsg("当前登录状态异常！");
            }
            //归属租户
            String companyCode = request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
//            companyCode="000001";
            if (StringUtils.isBlank(companyCode)) {
                return Result.failWithMsg("当前归属租户状态异常！");
            }
            if(Objects.isNull(iamRoleAuthorizedDto.getRoleCode())) {
                throw new RuntimeException("角色编码不可为空！");
            }
            iamRoleAuthorizedDto.setCompanyCode(companyCode);
            iamRoleAuthorizedDto.setCreatePerson(userName);
            iamRoleAuthorizedDto.setAdminRoleCode(adminRoleCode);
            log.info("Route=>IamRoleManagerController method=>roleAuthorizedApplication角色授权应用系统入参：{}", Json.toJsonString(iamRoleAuthorizedDto));

            iamRoleAuthorizedDto.getIamRoleAuthorizedApplicationDtos().forEach(iamRoleAuthorizedApplicationDto->{
                BeanUtils.copyProperties(iamRoleAuthorizedDto,iamRoleAuthorizedApplicationDto);
                if(Objects.isNull(iamRoleAuthorizedApplicationDto.getApplyCode())) {
                    throw new RuntimeException("应用编码不可为空！");
                }
                if(CollectionUtils.isEmpty(iamRoleAuthorizedApplicationDto.getMenuThreeVos())) {
                    log.warn("没有勾选应用下的任何菜单或按钮！");
                }
                iamRoleManagerService.roleAuthorizedApplication(iamRoleAuthorizedApplicationDto);
            });
            return Result.successWithMsg("角色授权应用系统成功！");
        } catch (Exception e) {
            log.error("Route==>IamRoleManagerController method=>roleAuthorizedApplication 角色授权应用系统异常: {}，入参：{}",e.getMessage(),Json.toJsonString(iamRoleAuthorizedDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：角色授权应用系统勾选的菜单或按钮，回填
     * @param iamMenuManagerAlreadySelectDto
     * @return Result
     */
    @PostMapping("/getAlreadyMenuThreeInfo")
    public Result getAlreadyMenuThreeInfo(HttpServletRequest request,@RequestBody IamMenuManagerAlreadySelectDto iamMenuManagerAlreadySelectDto) {
        try {
            //归属租户
            String companyCode = (String) request.getHeader(Constants.COMPANY_CODE);
            //companyCpde先使用伪数据
//            companyCode="000001";
            if (StringUtils.isBlank(companyCode)) {
                return Result.failWithMsg("当前归属租户状态异常！");
            }
            if(Objects.isNull(iamMenuManagerAlreadySelectDto.getRoleCode())){
                return Result.failWithMsg("角色编码不可为空！");
            }
            if(CollectionUtils.isEmpty(iamMenuManagerAlreadySelectDto.getApplyCodes())){
                return Result.failWithMsg("应用编码不可为空！");
            }
            iamMenuManagerAlreadySelectDto.setCompanyCode(companyCode);
            log.info("Route=>IamRoleManagerController method=>getAlreadyMenuThreeInfo 查询该角色下已勾选的菜单或按钮的入参：{}", Json.toJsonString(iamMenuManagerAlreadySelectDto));
            Set<String> alreadyMenuThreeInfo = iamRoleManagerService.getAlreadyMenuThreeInfo(iamMenuManagerAlreadySelectDto);
            return Result.success("查询该用户组下菜单树中已经勾选的菜单或按钮成功！",alreadyMenuThreeInfo);
        }catch (Exception e){
            log.error("Route=>IamRoleManagerController method=>getAlreadyMenuThreeInfo 查询该角色下已勾选的菜单或按钮异常：{},入参为：{}", e.getMessage(), Json.toJsonString(iamMenuManagerAlreadySelectDto));
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：根据userCode,查看一个用户(账户)的应用详情
     * @param iamApplyDetaislParam
     * @return Result
     */
    @PostMapping("/getApplicationDetails")
    public Result getApplicationDetails(HttpServletRequest request,@RequestBody IamApplyDetaislParam iamApplyDetaislParam) {
        try {
            //归属租户
            String companyCode = (String) request.getHeader(Constants.COMPANY_CODE);
            //companyCode先使用伪数据
//            companyCode="000001";
            if (StringUtils.isBlank(companyCode)) {
                return Result.failWithMsg("当前归属租户状态异常！");
            }
            if(StringUtils.isBlank(iamApplyDetaislParam.getUserCode())){
                return Result.failWithMsg("从Header中取不到用户id信息！");
            }
            iamApplyDetaislParam.setCompanyCode(companyCode);
            log.info("Route=>IamRoleManagerController method=>getApplicationDetails 查看一个用户(账户)的应用详情入参：{}", Json.toJsonString(iamApplyDetaislParam));
            return iamRoleManagerService.getApplicationDetails(iamApplyDetaislParam);
        }catch (Exception e){
            log.error("Route=>IamRoleManagerController method=>getApplicationDetails 查看一个用户(账户)的应用详情异常：{},入参为：{}", e.getMessage(), Json.toJsonString(iamApplyDetaislParam));
            return handleException(e,e.getMessage());
        }
    }



}
